package day05;

import java.util.Arrays;

//求数组元素的最大值
public class MaxOfArray {
    public static void main(String[] args) {
        /*
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; ++i) {
            Arrays.fill(arr, i, i + 1, i);
        }
        System.out.println(Arrays.toString(arr));
        int[] arr1 = new int[10];
        for (int i = 0; i < arr1.length; ++i) {
            arr1[i] = (int) (Math.random() * 99);
        }
        System.out.println(Arrays.toString(arr1));
        int max = arr1[0];
        for (int j : arr1) {
            if (j > max) max = j;
        }
        System.out.println(max);

         */
        int[] arr = new int[]{1, 100, 29, 44, 50, 11, 114, 514};

        int max = arr[0];//max=1 100 114 514
        for (int i : arr) {
            if (max < i) {
                max = i;
            }
        }
        arr = Arrays.copyOf(arr, arr.length + 1);
        arr[arr.length-1]=max;
        System.out.println(Arrays.toString(arr));

    }
}
